<?php

namespace App\Http\Controllers\Partner;

use App\Http\Controllers\ApiBaseController;
use Illuminate\Http\Request;
use DB;
use App\Models\PartnerModels\Partner;
class DouyinListAjaxController extends ApiBaseController
{
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->parames = $request->all();
    }

    //获取抖音无水印视频链接和音频
    function getDyVideoinfo(Request $request)
    {

        $itemid = $this->params;
        // print_r($itemid);exit();
        $soPartner = new Partner();
        $url = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={$itemid['itemid']}";
        $data = $this->getJson($url);
        // echo '<pre/>';  print_r($data);exit();
        //视频水印地址
        $watermark_url = $data['item_list'][0]['video']['play_addr']['url_list'][0];
        $voice_url = $data['item_list'][0]['music']['play_url']['url_list'][0];
        $id = $itemid['id'];
        $nowatermark_url = preg_replace("/playwm/", "play", $watermark_url);
        //  echo '<pre/>';  print_r($nowatermark_url);exit();
        if ($data['status_code'] == 0) {
            $soPartner->upVideoto($id, $nowatermark_url, $voice_url);
            return $this->returnJson(0, '操作成功');
        }
    }

//    //收藏榜单视频
//    function addcollectionid(Request $request)
//    {
//        if (!$request->session()->has('vip_user')) {
//            return redirect('admin/login');
//        }
//        $UserCollection = new UserCollection();
//        $vid = $this->params;
//        //  print_r($vid['vid']);
//        if (!$request->session()->has('vip_user')) {
//            return redirect('admin/login');
//        }
//        $id = session('vip_user')[0]['admin_id'];
//        $uservid = $UserCollection->getvidinfo($id, $vid['vid']);
//        if (empty($uservid)) {
//            $data = array(
//                'pid' => $id,
//                'vid' => $vid['vid'],
//                'status' => 1,
//                'create_time' => date('Y-m-d H:i:s', time()),
//                'update_time' => date('Y-m-d H:i:s', time()),
//            );
//            $UserCollection->db_insertGetId($data);
//           return $this->returnJson(0, '操作完成');
//            //   print_r($sdd);
//        } else {
//            return $this->returnJson(1, '已经收藏');
//        }
//    }



    //get请求
    function getJson($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);//为true，则会跟踪爬取重定向页面，否则，不会跟踪重定向页面
        curl_setopt($ch, CURLOPT_ENCODING, "");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书下同
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }

}